﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringFormatting
{
    class Fraction:IFormattable
    {
        private int num;
        private int denom;

        public Fraction(int num, int denom)
        {
            this.num = num;
            this.denom = denom;
        }

        public int Num
        {
            get
            {
                return num;
            }
            set
            {
                num = value;
            }
        }

        public int Denom
        {
            get
            {
                return denom;
            }
            set
            {
                denom = value;
            }
        }
        public string ToString(string format,
    IFormatProvider formatProvider)
        {
            if (format == "N")
            {
                return String.Format(
                    "{0}/{1}",num,denom);
            }
            else if (format == "R")
            {
                return String.Format(
                    "{0:0.##}", (double)num / denom);
            }
            else
            {
                return String.Format(
                    "{0}",(double)num / denom);
            }
        }	
    }
}
